package com.group11.invite.controller;

import com.group11.common.pojo.ResponseResult;
import com.group11.invite.domain.Invite;
import com.group11.invite.dto.IfInvite;
import com.group11.invite.dto.InviteDto;
import com.group11.invite.service.InviteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class InviteController {

    @Autowired
    private InviteService inviteService;

    @PostMapping("/add")
    public ResponseResult<Void> addInvite(@RequestBody Invite invite) {
        invite.setReply("");
        boolean save = inviteService.addInvite(invite);
        if (save) {
            return ResponseResult.SUCCESS;
        }
        return ResponseResult.FAILED;
    }

    @PostMapping("view")
    public ResponseResult<List<Invite>> viewInvite(@RequestHeader int id) {
        List<Invite> inviteByUserId = inviteService.getInviteByUserId(id);
        return new ResponseResult<>(inviteByUserId);
    }

    @PostMapping("reply")
    public ResponseResult<Void> reply(@RequestBody InviteDto inviteDto) {
        if (inviteService.reply(inviteDto)) {
            return ResponseResult.SUCCESS;
        }
        return ResponseResult.FAILED;
    }

    @PostMapping("delete")
    public ResponseResult<Void> deleteInvite(@RequestParam int id) {
        boolean b = inviteService.removeById(id);
        if (b) {
            return ResponseResult.SUCCESS;
        }
        return ResponseResult.FAILED;
    }

    @PostMapping("ifInvite")
    public ResponseResult<Invite> ifInvite(@RequestBody IfInvite ifInvite) {
        return new ResponseResult<>(inviteService.ifInvite(ifInvite.getJobId(), ifInvite.getResumeId()));
    }

}
